home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / jed10.zip / MYLIB.MAC < prev    next >
Text File  |  1993-02-26  |  7KB  |  161 lines

  1. ;---------------------------------------------------------------
  2. ;                         MYLIB.MAC
  3. ;       Macro library from ASSEMBLING FROM SQUARE ONE
  4. ;
  5. ;                                      by Jeff Duntemann
  6. ;                                      MASM/TASM
  7. ;                                      Last update 3/16/89
  8. ;---------------------------------------------------------------
  9.  
  10.  
  11. ;---------------------------------------------------------------
  12. ;   CLEAR    --  Clears the entire visible screen buffer
  13. ;   Last update 3/16/89
  14. ;
  15. ;      Caller must pass:
  16. ;      In VidAddress:  The address of the video refresh buffer
  17. ;      In ClearAtom:   The character/attribute pair to fill the
  18. ;                      buffer with.  The high byte contains the
  19. ;                      attribute and the low byte the character.
  20. ;      In BufLength:   The number of *characters* in the visible
  21. ;                      display buffer, *not* the number of bytes!
  22. ;                      This is typically 2000 for a 25-line screen
  23. ;                      or 4000 for a 50-line screen.
  24. ;      Action:         Clears the screen by machine-gunning the
  25. ;                      character/attribute pair in AX into the
  26. ;                      display buffer beginning at VidAddress.
  27. ;---------------------------------------------------------------
  28. Clear      MACRO VidAddress,ClearAtom,BufLength
  29.            les  DI,DWORD PTR VidAddress
  30.            mov  AX,ClearAtom
  31.            mov  CX,BufLength
  32.            rep  stosw
  33.            GotoXY 0,0
  34.            ENDM
  35.  
  36. ;---------------------------------------------------------------
  37. ;   RULER    --  Displays a "1234567890"-style ruler on-screen
  38. ;   Last update 11/25/91
  39. ;
  40. ;      Caller must pass:
  41. ;      In VidAddress: The address of the start of the video buffer
  42. ;      In Length:  The length of the ruler to be displayed
  43. ;      In ScreenW: The width of the current screen (usually 80)
  44. ;      In ScreenY: The line of the screen where the ruler is
  45. ;                  to be displayed (0-24)
  46. ;      In ScreenX: The row of the screen where the ruler should
  47. ;                  start (0-79)
  48. ;      Action:     Displays an ASCII ruler at ScreenX,ScreenY.
  49. ;---------------------------------------------------------------
  50. Ruler      MACRO VidAddress,Length,ScreenW,ScreenX,ScreenY
  51.            les    DI,DWORD PTR VidAddress
  52.            mov    AL,ScreenY   ; Move Y position to AL
  53.            mov    AH,ScreenW   ; Move screen width to AH
  54.            imul   AH           ; Do 8-bit multiply AL*AH to AX
  55.            add    DI,AX        ; Add Y offset into vidbuff to DI
  56.            add    DI,ScreenX   ; Add X offset into vidbuf to DI
  57.            shl    DI,1         ; Multiply by two for final address
  58.            mov    CX,Length    ; CX monitors the ruler length
  59.            mov    AH,07        ; Attribute 7 is "normal" text
  60.            mov    AL,'1'       ; Start with digit "1"
  61.  
  62. DoChar:    stosw               ; Note that there's no REP prefix!
  63.            add    AL,'1'       ; Bump the character value in AL up by 1
  64.            aaa                 ; Adjust AX to make this a BCD addition
  65.            add    AL,'0'       ; Basically, put binary 3 in AL's high nybble
  66.            mov    AH,07        ; Make sure our attribute is still 7
  67.            loop   DoChar       ; Go back & do another char until BL goes to 0
  68.  
  69.            ENDM
  70.  
  71. ;---------------------------------------------------------------
  72. ;   GOTOXY    --  Positions the hardware cursor to X,Y
  73. ;   Last update 3/5/89
  74. ;
  75. ;      Caller must pass:
  76. ;      In NewX: The new X value
  77. ;      In NewY: The new Y value
  78. ;        These are both 0-based; i.e., they assume a screen
  79. ;        whose dimensions are 24 by 79, not 25 by 80.
  80. ;      Action:  Moves the hardware cursor to the X,Y position
  81. ;               passed as NewX and NewY.
  82. ;---------------------------------------------------------------
  83. GotoXY     MACRO NewX,NewY
  84.            mov DH,NewY
  85.            mov DL,NewX
  86.            mov AH,02H        ; Select VIDEO service 2: Position cursor
  87.            mov BH,0          ; Stay with display page 0
  88.            int 10H           ; Call VIDEO
  89.            ENDM
  90.  
  91.  
  92. ;---------------------------------------------------------------
  93. ;   NEWLINE  --  Sends a newline sequence to DOS Standard Output
  94. ;                via DOS service 40H
  95. ;   Last update 3/16/89
  96. ;
  97. ;      Caller need not pass any parameters.
  98. ;      Action:  Sends a newline sequence DOS Standard Output
  99. ;---------------------------------------------------------------
  100.  
  101. Newline    MACRO
  102.            Write CRLF,2
  103.            ENDM
  104.  
  105. ;---------------------------------------------------------------
  106. ;   POKECHAR    --  Inserts a single character into a string
  107. ;   Last update 3/16/89
  108. ;
  109. ;      Caller must pass:
  110. ;      In Target:  The name of the string to be poked at
  111. ;      In TheChar: The character to be pocked into the string
  112. ;      In ToPos:   The 0-based position in the string to poke to
  113. ;      Action:     Pokes character passed in TheChar into string
  114. ;                  passed in Target to position passed in ToPos.
  115. ;                  The first character in the string is 0, etc.
  116. ;---------------------------------------------------------------
  117. PokeChar   MACRO Target,TheChar,ToPos
  118.            lea  BX,Target  ; Load the address of target string into BX
  119.            mov  BYTE PTR [BX+ToPos],TheChar  ; Move char into the string
  120.            ENDM
  121.  
  122. ;---------------------------------------------------------------
  123. ;   WRITE    --  Displays information to the screen via DOS
  124. ;                service 40: Print String to Standard Output
  125. ;   Last update 3/16/89
  126. ;
  127. ;      Caller must pass:
  128. ;      In ShowIt:     The name of the string to be displayed
  129. ;      In ShowLength: The length of the string to be displayed
  130. ;      Action:  Displays the string to DOS Standard Output
  131. ;---------------------------------------------------------------
  132. Write      MACRO ShowIt,ShowLength
  133.            mov BX,1          ; Selects DOS file handle 1: Standard Output
  134.            mov CX,ShowLength ; Length of string passed in CX
  135.            lea DX,Showit     ; Offset address of string is passed in DX
  136.            mov AH,40H        ; Select DOS service 40: Print String
  137.            int 21H           ; Call DOS
  138.            ENDM
  139.  
  140. ;---------------------------------------------------------------
  141. ;   WRITELN  --  Displays information to the screen via DOS
  142. ;                service 40H: Display to Standard Output, then
  143. ;                issues a newline
  144. ;   Last update 3/16/89
  145. ;
  146. ;      Caller must pass:
  147. ;      In ShowIt: The name of the string to be displayed
  148. ;      In ShowLength: The length of the string to be displayed
  149. ;      Action:  Displays the string in ShowIt, then issues a
  150. ;               newline.  Hardware cursor will move to the
  151. ;               left margin of the following line.  If the
  152. ;               display is to the bottom screen line, the
  153. ;               screen will scroll.
  154. ;      Calls: Write
  155. ;---------------------------------------------------------------
  156.  
  157. Writeln    MACRO ShowIt,ShowLength
  158.            Write ShowIt,ShowLength  ; Display the string proper through Write
  159.            Write CRLF,2             ; Display the newline string through Write
  160.            ENDM
  161.